
function clickClientPrice(){
	var obj=$("#bag").html("");
	obj.load("clientCostPrice",function(response,status,xhr){
		var data="clientName=&currentPages=";
		//调用显示客户列表信息的方法
		showClientPriceInfo(data);
	});
}

//按条件查询客户基本信息
function clientPriceSel(){
	//获取查询条件
	var data="name="+$("#clientNames").val();
	showclientPriceInfo(data);
}

//显示客户客户报价信息
function showClientPriceInfo($data){
	var url="/trade-wzj-web/ClientInfoQuotaControllerYang/getAllClientPriceList";
	
	var client = postMethod(url,"POST",$data);
	
	//获取结果集合
	var list = client.list;
	
	//获取查询条件
	var selCondition = $("#clientPriceNames").val();
	
	var clientTable="";
	if(list.length>=0){
		for(var i=0;i<list.length;i++){
			clientTable = clientTable+"<tr>"+
    		"<td>"+list[i].clientQuotaID+"</td>"+
    		"<td>"+list[i].clientInfo.clientName+"</td>"+
    		"<td>"+list[i].clientQuotaDate+"</td>"+
    		"<td>"+list[i].pay.payStateName+"</td>"+
    		"<td><a href='#' onclick='checkClientDetailPrice("+list[i].id+","+list[i].clientInfo.clientInfoID+")'><span class='glyphicon glyphicon-search'></span></a>&nbsp;&nbsp;<a href='#' onclick='updateClientPriceOpen("+list[i].clientInfoID+","+client.pageNum+",\""+selCondition+"\");'><span class='glyphicon glyphicon-pencil'></span></a>&nbsp;&nbsp;<a href='#' onclick='delClientPriceTable("+list[i].clientInfoID+","+client.pageNum+",\""+selCondition+"\")'><span class='glyphicon glyphicon-remove'></span></a></td>"+
    		"</tr>";
		}
	}
	var tbody = $("#costAllClientTable tbody").html("");
	tbody.append(clientTable);
	var page = getPageClientPrice(client);
	var pageTable = $("#clientPricePage").html("");
	
	pageTable.append(page);
}

//获取页码信息
function getPageClientPrice($clientList){
	var page="";
	
	var con = $("#clientPriceNames").val();
	page = page+"<div class='row' style='margin:0px'>" +
	"<div class='col-md-2 col-sm-2 col-xs-2' style='padding-top:0.7rem'>"+
		"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
	"</div>"+
	"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"
	+"<nav aria-label='Page navigation'>"+
"<ul class='pagination pagination-sm'>";
	if($clientList.prePage>0){
		page = page+"<li><a href='#' onclick='getPagesClientPrice("+$clientList.firstPage+",\""+con+"\")'>首页</a></li>"+
		"<li><a href='#' onclick='getPagesClientPrice("+$clientList.prePage+",\""+con+"\")'>上一页</a></li>";
				
	}
	if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
		page = page+"<li><a href='#' onclick='getPagesClientPrice("+$clientList.nextPage+",\""+con+"\")'>下一页</a></li>"+
		"<li><a href='#' onclick='getPagesClientPrice("+$clientList.lastPage+",\""+con+"\")'>末页</a></li>";
	}
	page = page+"</li>"+
"</ul>"+
"</nav>"+
"</div>"+
"</div>";
	return page;
	
}

//分页功能
function getPagesClientPrice($page,$object){
	var data="name="+$object+"&currentPages="+$page;
	showClientPriceInfo(data);
}


//删除客户报价信息信息
function delClientPriceTable($delId,$pageNum,$object){
	var ensure = confirm("确定删除此信息吗?");
	
	if(ensure==false){
		return;
	}
	//获取删除条件
	var data="clientInfoId="+$delId;
	var url="/trade-wzj-web/testYu/test";
	var result =postMethod(url,"POST",data);
	console.info(result);
	if(result==""){
		alert("删除成功!");
	}else{
		alert(result);
	}
	
	var selData = "name="+$object+"&currentPages="+$pageNum;
	showClientPriceInfo(selData);
}



//新增客户基本信息
function addClientPrice(){
	var tables = $("#addClientPriceTable");
	tables.html("");
	var tableAdd = "<tr>" +
			"<td>报价编号*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='此信息不能为空' name='clientName' ></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>客户名称*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='不能为空' name='clientContacts'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>报价日期*：</td>" +
			"<td><input type='text' name='clientPhone' datatype='*' nullmsg='不能为空'  class='form-control'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>报价截止日期*：</td>" +
			"<td><input type='text' name='clientAddress' datatype='*' nullmsg='客户地址不能为空' class='form-control'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>付款条件*：</td>" +
			"<td><input type='text' name='clientEmail' datatype='*' nullmsg='不能为空' class='form-control'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>备注*：</td>" +
			"<td><input type='text' name='clientFax' datatype='*' nullmsg='不能为空' class='form-control'></td>"+
			"<td></td>"+
			"</tr>";
	tables.append(tableAdd);
	$("#addclientPrice").modal("toggle");
}

//保存客户基本信息添加
function saveClientPrice(){
	var addClientForm = $("#addClientPriceForm").Validform({
		tiptype:1
	});
	
	var bool = addClientForm.check();
	if(bool==false){
		$("#addClientPriceS").popover("toggle");
		return;
	}
	var data = $("#addClientPriceForm").serialize();
	//获取提交路径
	var url="/trade-wzj-web/tests/kfAdd";
	var flag = postMethod(url,"POST",data);
	
	if(flag==""){
		alert("添加成功!");
		
	}else{
		alert("添加失败");
	}
	showClientPriceInfo(null);
}

//打开要修改的客户基本信息页面
function updateClientPriceOpen($updateId,$object,$num){
	//定义要修改的对象
	var data="updateId="+$updateId+"&name="+$object+"&num="+$num;
	//获取提交路径
	var url="";
	//调用提交方法
	var result = postMethod(url,"POST",data);
	var tables = $("#updateClientPriceTable").html("");
	
	var tableAdd = "<tr>" +
			"<td>报价编号*：</td>" +
			"<td><input type='text' class='form-control' readonly='readonly' value='"+result.clientName+"'><input type='hidden' value='"+result.id+"'></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>客户名称*：</td>" +
			"<td><input type='text' class='form-control' datatype='*' nullmsg='不能为空' name='clientContacts' value='"+result.clientContacts+"' required></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>报价日期*：</td>" +
			"<td><input type='text' name='clientPhone' datatype='n11' errormsg='号码有误!' class='form-control' value='"+result.clientPhone+"' required></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>报价截止日期*：</td>" +
			"<td><input type='text' value='"+result.clientAddress+"' name='clientAddress' datatype='*' class='form-control' required></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>付款条件*：</td>" +
			"<td><input type='text' value="+result.clientEmail+" name='clientEmail' datatype='*' class='form-control' required></td>"+
			"<td></td>"+
			"</tr>"+
			"<tr>" +
			"<td>备注*：</td>" +
			"<td><input type='text' value='"+result.clientFax+"' name='clientFax' datatype='*' class='form-control' required></td>"+
			"<td></td>"+
			"</tr>";
	tables.append(tableAdd);
	console.info(tableAdd);
	$("#updateClientPriceModal").modal("toggle");
}

//修改客户基本信息按钮方法
function updateClientPrice(){
	
	var updateClientForm = $("#updateClientPriceForm").Validform({
		tiptype:1
	});
	var bool = updateClientForm.check();
	if(!bool){
		$("#updateClientPriceSub").popover("toggle");
		return;
	}
	var formData = $("#updateClientPriceForm").serialize();
	//获取提交路径
	var url="";
	var result = postMethod(url,"POST",data);
	console.info(result);
	var $data = "";
	var list = showClientPriceInfo($data);
	
}


//通过客户名称查询客户报价信息
function getClientPriceById(){
	var vi=$("#clientPriceNames").val();
	var data="clientName="+vi+"&currentPages=";
	
	showClientPriceInfo(data);
}